import WebpackLicense from '@components/WebpackLicense';
import PropertyType from '@components/PropertyType';
import { Tabs, Tab } from '@theme';

<WebpackLicense from="https://webpack.js.org/configuration/entry-context/#context" />

# Context

<PropertyType
  type="string"
  defaultValueList={[{ defaultValue: 'process.cwd()' }]}
/>

The `context` configuration is used to set the base directory for Rspack builds.

`context` is an absolute path that is used as the base path for relative paths in Rspack configurations such as [entry](/config/entry) and [output](/config/output).

By default, Rspack uses the current working directory of the Node.js process as the base directory. In most cases, it is recommended to set a base directory manually, rather than relying on the current working directory of Node.js.

## Example

For example, you can use [`__dirname`](https://nodejs.org/docs/latest/api/modules.html#__dirname) as the base directory:

<Tabs>
  <Tab label="ESM">

```js title="rspack.config.mjs"
import { dirname } from 'node:path';
import { fileURLToPath } from 'node:url';

const __dirname = dirname(fileURLToPath(import.meta.url));

export default {
  context: __dirname,
  entry: {
    main: './src/index.js',
  },
};
```

  </Tab>
  <Tab label="CJS">

```js title="rspack.config.cjs"
module.exports = {
  context: __dirname,
  entry: {
    main: './src/index.js',
  },
};
```

  </Tab>
</Tabs>

In the above example, the `main` entry will be resolved based on the `path.join(__dirname, './src/index.js')` path.
